/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2024-03-11 17:01:43
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-05-15 14:09:57
 * @FilePath: /yt-devops/lib/pages/devices/device_controll/device_set_page/device_set_page_view.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/brn/brn_bottom_button_panel.dart';
import 'package:yt_devops/pages/devices/device_controll/device_controll_utils.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import '../device_set_widget/device_set_widget.dart';
import 'device_set_page_controller.dart';

class DeviceSetPage extends GetView<DeviceSetPageController> {
  DeviceSetPage({Key? key}) : super(key: key);

  final GlobalKey<DeviceSetWidgetState> childKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DeviceSetPageController>(
      builder: (controller) => Scaffold(
        resizeToAvoidBottomInset: true,
        appBar: AppBarWidget.defaultAppBar(ResKey.parameterSets.tr),
        body: Column(
          children: [
            DeviceControllUtils.createHead(
                controller.serviceConfigModel.name ?? '',
                isShowSetButton: false),
            Expanded(
                child: DeviceSetWidget(
              key: childKey,
              deviceId: controller.deviceId,
              serviceConfigModel: controller.serviceConfigModel,
              data: controller.dataSource,
            )),
          ],
        ),
        bottomNavigationBar: DecoratedBox(
          decoration: const BoxDecoration(color: Colour.white),
          child: SafeArea(
            child: YtBrnBottomButtonPanel(
              mainButtonName: 'siteMonitor.issueParameters'.tr,
              mainButtonOnTap: () {
                if (FocusScope.of(context).hasFocus) {
                  FocusScope.of(context).unfocus();
                }

                childKey.currentState!.sendCommand(
                    confirmHandler: (success, {Map<String, dynamic>? data}) {
                  Get.back(result: success);
                });
              },
              secondaryButtonOnTap: () {
                Get.back(result: false);
              },
              secondaryButtonName: ResKey.cancel.tr,
              enableSecondaryButton: true,
              secondaryButtonBorder: Border.all(color: Colour.dividerColor),
            ),
          ),
        ),
      ),
    );
  }
}
